package com.baikeyang.modules;

import org.apache.shiro.codec.Base64;
import org.apache.shiro.codec.Hex;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.*;
import org.junit.Assert;
import org.junit.Test;

/**
 * Created by lenovo on 2018/6/29.
 */
public class ShiroTest1 {

    @Test
    public void test2() {
        String str = "hello";
        String base64Encoded = Hex.encodeToString(str.getBytes());
        String str2 = new String(Hex.decode(base64Encoded.getBytes()));
        Assert.assertEquals(str, str2);
    }

    @Test
    public void test1(){
        String str = "hello";
        String base64Encoded = Base64.encodeToString(str.getBytes());
        String str2 = Base64.decodeToString(base64Encoded);
        Assert.assertEquals(str, str2);
    }

    @Test
    public void test3(){
        String str = "hello";
        String salt = "123";
        String md5 = new Md5Hash(str, salt, 6).toString();
        System.out.println(md5);
    }

    @Test
    public void test4(){
        String str = "hello";
        String salt = "123";
        String sha1 = new Sha256Hash(str, salt).toString();
        System.out.println(sha1);

        String sha2 = new Sha512Hash(str, salt).toString();
        System.out.println(sha2);

        String sha3 = new Sha1Hash(str, salt).toString();
        System.out.println(sha3);

        String sha4 = new SimpleHash("SHA-1", str, salt).toString();
        System.out.println(sha4);
    }

    @Test
    public void test5(){
        SecureRandomNumberGenerator randomNumberGenerator =
                new SecureRandomNumberGenerator();
        randomNumberGenerator.setSeed("123".getBytes());
        String hex = randomNumberGenerator.nextBytes().toHex();
        System.out.println(hex);
    }





}
